-- Settings for when a player joins
	-- XYZ coördinates
	local joinX = get ("joinX")
	local joinY = get ("joinY")
	local joinZ = get ("joinZ")
	local joinR = get ("joinR")
	-- Weapon and ammo
	local joinWeapon = get ("joinWeapon")
	local joinAmmo = get ("joinAmmo")
	-- Skin that player gets
	local joinSkin = get ("joinSkin")

-- Settings for when a player dies
	-- XYZ coördinates
	local spawnX = get ("spawnX")
	local spawnY = get ("spawnY")
	local spawnZ = get ("spawnZ")
	local spawnR = get ("spawnR")
	-- Weapon and ammo
	local spawnWeapon = get ("spawnWeapon")
	local spawnAmmo = get ("spawnAmmo")
	-- Skin that player gets
	local spawnSkin = get ("spawnSkin")

-- Settings for the amounts of money
	-- Money the killer gets
	local killerMoney = get ("killerMoney")
	-- Money removed from player when they die
	local deadPlayerMoney = get ("deadPlayerMoney")
	-- Money you get when you join
	local joinMoney = get ("joinMoney")

-- Functions
-- This function spawns players when they join
function spawnOnLogin()
	local playeraccount = getPlayerAccount (source)
	local newplayer = getAccountData (playeraccount, "rpg.newplayer")
	if (newplayer) then
		outputChatBox ("Account data loaded. Welcome back!", source)
	else
		spawnPlayer(source, joinX, joinY, joinZ, joinR , joinSkin)
		fadeCamera(source, true)
		setCameraTarget(source, source)
		giveWeapon(source, joinWeapon, joinAmmo)
		givePlayerMoney(source, joinMoney)
	end
end

-- This function spawns players after they died
function spawnOnDead(ammo, killer, weapon, bodypart)
	outputChatBox(getPlayerName(source).." died.")
	if (killer) and (killer ~= source) then
		givePlayerMoney(killer, killerMoney)
	end
	setTimer(spawnPlayer, 3000, 1, source, spawnX, spawnY, spawnZ, spawnR, spawnSkin)
	setTimer(takePlayerMoney, 3000, 1, source, deadPlayerMoney)
	setTimer(outputChatBox, 3000, 1, "You had to pay the hospital fee. It cost you 200 dollar.", source)
	setCameraTarget(source, source)
	setTimer(giveWeapon, 3000, 1, source, spawnWeapon, spawnAmmo)
end

-- Event handlers
addEventHandler("onPlayerLogin", getRootElement(), spawnOnLogin)
addEventHandler("onPlayerWasted", getRootElement(), spawnOnDead)